package ans.p118;

import test.Entrance;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * #      118
 * 名称   杨辉三角
 * 链接   https://leetcode-cn.com/problems/pascals-triangle
 * 题解   [1294](https://leetcode-cn.com/problems/pascals-triangle/solution)
 * 通过率 70.4%
 * 难道   简单
 */

public class Solution {
    @Entrance
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> res = new LinkedList<>();
        for (int i = 1; i < numRows + 1; i++) {
            Integer[] ints = new Integer[i];
            ints[0] = 1;
            ints[i - 1] = 1;
            if (i > 2) {
                for (int j = 1; j < i - 1; j++) {
                    ints[j] = res.get(i - 2).get(j) + res.get(i - 2).get(j - 1);
                }
            }
            res.add(Arrays.asList(ints));
        }
        return res;
    }
}